import 'package:native_dart_package/http/request/exception/api_exception.dart';
import 'package:yt_devops/configs.dart';

import '../predicates.dart';

class DeviceServices {
  // 设备列表
  Future getDevicelist(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/device/deviceList',
        queryParameters: params, onError: onError);
  }

  ///获取设备设备列表
  Future getSiteDeviceList(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/monitor/device/getDeviceList',
        queryParameters: params, onError: onError);
  }

  Future getProductTypelist() {
    return Configs.httpClient.get(
      '$iot/product/getProductTypeTree',
    );
  }

  // 获取设备基础信息
  Future getDeviceInfo(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$oss/device/detailsNoPermission',
      queryParameters: params,
      onError: onError,
    );
  }

  // 更新设备信息
  Future updateDeviceInfo(params) {
    return Configs.httpClient
        .post('$iot/device/updateNoPermission', data: params);
  }

  // 获取站点列表下拉框
  Future getSiteList(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/getList', onError: onError);
  }

  // 获取设备信息
  Future getDeviceBySn(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/device/getDeviceBySn',
        queryParameters: param, onError: onError);
  }

  // 储能功率曲线
  Future getPowerCurve(param) {
    return Configs.httpClient
        .get('$iot/device/es/getPowerCurve', queryParameters: param);
  }

  // 储能设备充放电量
  Future getEssChargeDischargeTrends(param) {
    return Configs.httpClient
        .get('$iot/device/essChargeDischargeTrends', queryParameters: param);
  }

  // 获取设备状态数量
  Future getDeviceStatusNum() {
    return Configs.httpClient.get('$iot/device/getDeviceStatusNum',
        queryParameters: {'isConfine': 0});
  }

  // 获取电池堆下面的电池簇
  Future getBatteryDevices(param) {
    return Configs.httpClient.get(
        '$oss/site/monitor/device/app/getBatteryDevices',
        queryParameters: param);
  }

  // 获取子设备
  Future getSubDevices(param) {
    return Configs.httpClient
        .get('$oss/device/app/subDevice', queryParameters: param);
  }

  // 根据时间段获取某个设备的某个key的历史数据(曲线数据可用该接口)
  Future getDeviceDataForHistoryList(param) {
    return Configs.httpClient.get(
        '$iot/processRealData/queryDeviceDataForHistoryList',
        queryParameters: param);
  }

  // 获取物模型
  Future getDeviceProperty(param) {
    return Configs.httpClient
        .get('$iot/model/getThingsModeByProductId', queryParameters: param);
  }

  // 获取物模型
  Future getNewDeviceProperty(param) {
    return Configs.httpClient
        .get('$oss/product/getThingsModeByProductId', queryParameters: param);
  }

  // 获取新的物模型 oss服务
  Future getDeviceNewProperty(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/product/getThingsModeByProductId',
        queryParameters: param, onError: onError);
  }

  /// 获取并机信息
  Future getDeviceEsGroup(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$iot/device/getEsGroup',
      queryParameters: param,
      onError: onError,
    );
  }

  // 配置通信参数
  Future updateDeviceCommunicationConfigNoAuth(param) {
    return Configs.httpClient
        .put('$iot/device/updateDeviceCommunicationConfigNoAuth', data: param);
  }

  // 获取关联设备
  Future getAssociateDevicesByDeviceIdAndType(param) {
    return Configs.httpClient.get(
        '$iot/device/getAssociateDevicesByDeviceIdAndType',
        queryParameters: param);
  }

  // 获取站点设备树
  Future deviceTree(param) {
    return Configs.httpClient.get(
        '$iot/siteSystemConfiguration/condition/deviceTree',
        queryParameters: param);
  }

  // 获取站点设备树下面的采集点
  Future deviceTreeObserver(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
        '$iot/siteSystemConfiguration/dataSource/deviceParamList',
        queryParameters: param,
        onError: onError);
  }

  // 获取站点设备树
  Future addDeviceAssociate(param) {
    return Configs.httpClient
        .post('$iot/device/addDeviceAssociate', data: param);
  }

  // 获取第三方站点
  Future getThirdSiteList(param) {
    return Configs.httpClient
        .get('$iot/thirdSite/getThirdSiteList', queryParameters: param);
  }

  /// EMS远程控制
  Future deviceRemoteSetting(param) {
    return Configs.httpClient.post(
      '$oss/site/monitor/device/remoteSetting',
      data: param,
    );
  }

  /// 解绑设备
  Future unbindingDevice(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$iot/device/deviceUnbindSite', data: param, onError: onError);
  }

  /// 获取所属单元
  Future getOwningUnit({bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/product/subsystemList',
        queryParameters: {'isConfine': 0}, onError: onError);
  }

  /// 获取产品详情
  Future getProductDetail(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$iot/product/getProduct',
      queryParameters: param,
      onError: onError,
    );
  }

  /// 获取产品类型
  Future getDeviceType(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/product/getAllProductType',
        queryParameters: param, onError: onError);
  }

  /// 获取产品型号列表
  Future getProductModelList(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/product/getAllProductsByproductType',
        queryParameters: param, onError: onError);
  }

  /// 获取第三方关联站点
  Future getThreePartSite(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/thirdSite/getThirdSiteList',
        queryParameters: param, onError: onError);
  }

  /// 根据产品id获取通信信息类型和配置信息类型
  Future deviceAccessConfigType(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/device/configTypeByProductId',
        queryParameters: param, onError: onError);
  }

  /// 添加没有的设备到平台
  Future postDeviceAccess(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$oss/appDevice', data: param, onError: onError);
  }

  /// 绑定sn设备
  Future postSnDeviceAccess(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$iot/device/bindDevice', data: param, onError: onError);
  }

  /// 配置电表,或者光伏逆变器.储能
  Future meterConfigs(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.put(
        '$iot/device/updateDeviceCommunicationConfigNoAuth',
        data: param,
        onError: onError);
  }

  ///设备配置信息数据(关联设备)
  Future configsRelationDevice(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.put('$iot/device/updateDeviceProductConfigNoAuth',
        data: param, onError: onError);
  }

  ///市电电价新增
  Future siteMainsAdd(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$oss/site/mains/app/save', data: param, onError: onError);
  }

  ///市电电价修改
  Future siteMainsUpdate(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$oss/site/mains/app/update', data: param, onError: onError);
  }

  ///上网电价新增
  Future sitePhotovoltaicAdd(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$oss/site/internet/app/save', data: param, onError: onError);
  }

  ///上网电价修改
  Future sitePhotovoltaicAUpdate(param,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$oss/site/internet/app/update', data: param, onError: onError);
  }

  ///充电电价新增
  Future siteChargeAdd(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$oss/site/charge/app/save', data: param, onError: onError);
  }

  ///充电电价修改
  Future siteChargeUpdate(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$oss/site/charge/app/update', data: param, onError: onError);
  }

  // ///获取采集点列表
  // Future siteObserverList(param, {bool Function(ApiException)? onError}) {
  //   return Configs.httpClient.get(
  //       '$iot/siteSystemConfiguration/condition/deviceTree',
  //       queryParameters: param,
  //       onError: onError);
  // }

  ///获取站点监控列表
  Future getSiteObserverConfig(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
        '$iot/siteSystemConfiguration/dataSource/selectAllDeviceListBySiteId',
        queryParameters: param,
        onError: onError);
  }

  ///ems从设备网络状态列表
  Future getEmsDeviceNet(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/es/ems_slave_device_network',
        queryParameters: param, onError: onError);
  }

  ///更改站点监控监测点状态开启或者关闭
  Future siteObserverObserverStatus(param,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.put(
        '$iot/siteSystemConfiguration/dataSource/updateFlag',
        queryParameters: param,
        onError: onError);
  }

  ///更改监测点的采集点数据
  Future siteObserverObserverData(param,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.put(
        '$iot/siteSystemConfiguration/dataSource/update',
        data: param,
        onError: onError);
  }

  /// 根据储能设备id获取模式
  Future getEnergyStorageMode(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$iot/device/getEsDeviceIsMasterOrSalve',
      queryParameters: param,
      onError: onError,
    );
  }

  /// 获取app版本号
  Future getAppVersion(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$oss/version/listApp',
      queryParameters: param,
      onError: onError,
    );
  }

  /// 获取app(安卓)下载地址
  Future getAppDownloadUrl(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$oss/prodApi/uc/fileUrl',
      queryParameters: param,
      onError: onError,
    );
  }

  Future refreshRemoteSetting(
    param,
  ) {
    return Configs.httpClient.post(
      '$oss/device/remote_setting',
      data: param,
    );
  }

  /// 获取充电枪电压电流曲线
  Future getGunVoltageAndCurrent(param,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/ytcharging/getChargeDayCurve',
        queryParameters: param, onError: onError);
  }

  /// 获取充电枪温度曲线
  Future getGunTemperature(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/ytcharging/getChargeTCurve',
        queryParameters: param, onError: onError);
  }

  /// 获取soc电能曲线
  Future getSocElectricity(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/ytcharging/ytOrder/curve',
        queryParameters: param, onError: onError);
  }

  /// 获取soc电能曲线
  Future getDeviceDataQueryHistorical(param,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$iot/deviceData/queryHistorical', data: param, onError: onError);
  }

  /// 获取充电枪订单列表
  Future getGunOrderList(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/ytcharging/ytOrder/page',
        queryParameters: param, onError: onError);
  }

  /// 获取充电枪订单详情
  Future getGunOrderDetail(param, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/ytcharging/ytOrder/page',
        queryParameters: param, onError: onError);
  }

  /// 获取充电桩实时功率
  Future getChargeStationRealTimePower(params) {
    return Configs.httpClient.get(
      '$iot/ytcharging/getPowerChart',
      queryParameters: params,
    );
  }

  /// 获取日充电桩充电电量日充电次数
  Future getDailyChargeCapacityAndFrequency(params) {
    return Configs.httpClient.get(
      '$iot/ytcharging/getChargeElecAndCount',
      queryParameters: params,
    );
  }

  /// 获取终端设备 {{iot}}/ytcharging/getTerminal
  Future getChargeTerminalDevice(params) {
    return Configs.httpClient.get(
      '$iot/ytcharging/getTerminal',
      queryParameters: params,
    );
  }

  /// 删除终端
  Future delTerm(params) {
    return Configs.httpClient.delete(
      '$iot/ytcharging/delTerm',
      queryParameters: params,
    );
  }

  /// 添加充电桩终端
  Future addChargeTerm(params) {
    return Configs.httpClient.post(
      '$iot/ytcharging/addTerminal',
      data: params,
    );
  }

  /// 查询充电桩终端
  Future getChargeTerm(params) {
    return Configs.httpClient.get(
      '$iot/ytcharging/getChargeTerm',
      queryParameters: params,
    );
  }

  /// 编辑充电桩终端
  Future updateChargeTerm(params) {
    return Configs.httpClient.put(
      '$iot/ytcharging/termBindMainServer',
      data: params,
    );
  }

  Future getDeviceCountBySiteId(params) {
    return Configs.httpClient.get(
      '$iot/device/getDeviceCountBySiteId',
      queryParameters: params,
    );
  }

  /// 调整设备管理列表页面排序
  Future updateDeviceModifySort(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.put(
      '$iot/device/modifySort',
      data: params,
      onError: onError,
    );
  }

  /// 查询设备数据采集点
  Future deviceParamList(
    Map<String, dynamic> params,
  ) {
    return Configs.httpClient.get(
      '$iot/siteSystemConfiguration/dataSource/deviceParamList',
      queryParameters: params,
    );
  }

  ///查询字段的历史信息
  Future queryDeviceDataForHistoryList(Map<String, dynamic> params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
        '$iot/processRealData/queryDeviceDataForHistoryList',
        queryParameters: params,
        onError: onError);
  }

  /// 分时电量信息
  //   GET {{oss}}/device/ems/getTimeBattery
  //   接口ID：179170305
  //   接口地址：https://app.apifox.com/link/project/3172698/apis/api-179170305
  Future getTimeBatteryInfo(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$oss/device/ems/getTimeBattery',
      queryParameters: params,
      onError: onError,
    );
  }

  /// 将友盟的token传给后台
  Future saveToken(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.post(
      '$preApi/app/saveToken',
      data: params,
      onError: onError,
    );
  }

  // 获取费率设置
  Future getRateSetting(Map<String, dynamic> params) {
    return Configs.httpClient.get(
      '$iot/deviceSendData/getLatestDeviceSendDada',
      queryParameters: params,
    );
  }

  // 费率设置
  Future editRateSetting(Map<String, dynamic> params) {
    return Configs.httpClient.post(
      '$iot/deviceSendData/deviceSend',
      data: params,
    );
  }
}
